package com.bupt.listener;

import com.bupt.pojo.VoucherOrder;
import com.bupt.service.IVoucherOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class MQListener {

//    private final IOrderService orderService;
    private final IVoucherOrderService voucherOrderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "youdp.voucher.queue", durable = "true"),
            exchange = @Exchange(name = "voucher.topic", type = ExchangeTypes.TOPIC),
            key = "voucher.success"
    ))
    public void listenPaySuccess(VoucherOrder voucherOrder){
        System.err.println(voucherOrder);
        voucherOrderService.createVoucherOrder(voucherOrder);
//        orderService.markOrderPaySuccess(orderId);
    }
}
